package com.iss.controller;

import com.iss.service.UserService1;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(urlPatterns ="/user")
public class UserController extends HttpServlet {

    private UserService1 userService = new UserService1();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        String action = req.getParameter("action");

        doAction(action,req,resp);
    }

    private void doAction(String action, HttpServletRequest req, HttpServletResponse resp) throws IOException {
        if(action.equals("login"))
        {
            PrintWriter out = resp.getWriter();

            String username = req.getParameter("username");
            Boolean flag=  userService.login(username);
            out.println(flag);
        }

        if(action.equals("unuse")){
            try {
                resp.getWriter().println("unuse");
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
